#include <FunctionsPluginBullet.h>
#include <PhysicsWorld.h>
#include <NodeInfoContainerBullet.h>
#include <EObject.h>
#include <BulletClassDataSource/RigidBodyBullet.h>
btCollisionObject *FunctionsPluginBullet::findCollisionObjByMTName(const std::string &mtName)
{
    btCollisionObject* resultObj = NULL;
    const btCollisionObjectArray* collisionObjArray = PhysicsWorld::instance()->getCollisionObjArray();
    int i;
    for(i = 0; i < collisionObjArray->size(); i++)
    {
        btCollisionObject* object_ptr = collisionObjArray->at(i);

        NodeInfoContainerBullet* nodeInfo = (NodeInfoContainerBullet*)(object_ptr->getUserPointer());

        EObject* eobj = nodeInfo->getObjectInspectorItem()->getObjectPtr().data();
        RigidBodyBullet* rigidBodyBullet = dynamic_cast<RigidBodyBullet*>(eobj);
        if(rigidBodyBullet != NULL)
        {
            QString transName = rigidBodyBullet->getTransformNodeName();
            if(transName == QString::fromStdString(mtName))
            {
                resultObj = rigidBodyBullet->getRigidBody();
                break;
            }
        }

    }
    return resultObj;
}
